package top.didi.study.study.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter(filterName = "EnodingFilter", urlPatterns = "/*")
public class EncodingFilter implements Filter {

    public static final String UTF8 = "UTF-8";
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //设置编码
        servletRequest.setCharacterEncoding(UTF8);
        servletResponse.setCharacterEncoding(UTF8);
        System.out.println("编码拦截器同一处理：" + UTF8);
        //放行请求
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
